﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Dev.Control;
using SfcorpDLL.ety;
using SfcorpDLL.biz;
using TT.Common;
using TT.ORM;
using Billing.ety;
using Billing;
using GT.ORM;
using Dev.Control.Form;
using GT.ReportDLL.Biz;
using GT.ReportDLL.ety;
using System.Collections;
using DevExpress.XtraGrid.Views.Base;
using GT.FormsUI.Query;

namespace Sfcorp.form
{
    public partial class frmSearchSummary : BaseFormDev
    {
        etyBillParams eyBillRq = new etyBillParams();
        bool isBilled = false;
        bizSeachDtl bzAgyBnsSearch;
        etyFrtAgyBns eySqlWhere = new etyFrtAgyBns();

        //IList<etyChargeDtl> ilModifyBill = new List<etyChargeDtl>();//记录修改过的费用列表
        //IList<etyChargeDtl> ilDeleteBill = new List<etyChargeDtl>();//记录删除过的费用列表
        //IList<etyChargeDtl> ilCreateBill = new List<etyChargeDtl>();//记录过的费用列表

        IList<etyFrtAgyBns> ilImageList = new List<etyFrtAgyBns>();
        IList<etyFrtAgyBns> ilAddImgList = new List<etyFrtAgyBns>();
        IList<etyFrtAgyBns> ilDelImgList = new List<etyFrtAgyBns>();
        public string ContractNo ="";// "DK--201504--0008";
        public frmSearchSummary()
        {
            InitializeComponent();

        }

        private string formSta;
        public string FormSta
        {
            set
            {
                formSta = value;
                delFabConList = new List<etyFrtAgyBns>();
                RemoveDtlControlEvent();
                switch (formSta)
                {
                    case "A":
                        lblBar.Caption = "新建状态";
                        btnDelete.Enabled = false;
                        break;
                    case "E":
                        lblBar.Caption = "编辑状态";
                        btnDelete.Enabled = true;
                        curContractNo = txtContract_No.Text;//保存起正在编辑的业务单号，以防业务单号被修改
                        break;
                    default:
                        break;
                }
            }
            get
            {
                return formSta;
            }
        }
        private string curContractNo;

        string sGridHead = string.Empty;

        private void frmAgyBns_Load(object sender, EventArgs e)
        {
            //刷新界面所需要的数据
            TT.Module.RefreshTable.BaseTableRefreshByTables(string.Empty, false);

            //业务单
            ggcDtl.GridView = this.gridView1;
            ggcDtl.GridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.Click;
            CreateGridHeard(null);
            //ggcDtl.ColumnsMappingCreate(sGridHead);
            //this.winUtil.LoadGridLayout(ggcDtl);
            ggcDtl.GridView.OptionsView.ShowGroupPanel = true;
            //计费单
            isInitBillGrid = true;
            bzAgyBnsSearch = new bizSeachDtl(global.basSysPara);

            gridView1.OptionsBehavior.Editable = false;

            BindCombBox();
            ClearForm();
            //要设置一下.IndicatorWidth，要不然列会被遮挡
            //this.gridView1.IndicatorWidth = 40;
        }

        private void BindCombBox()
        {
            cboPort_Id.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilPort);
            cboI_E_Id.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCIE);
            cboFee_Way_Id.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilFeeWay);
            cboCollaborate_Id.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCollaboRate);
            cboCustomer_Id.DataSource = dataProcessor.CopyIList<SfcorpDLL.ety.etyCustomer>(global.ilCustomer);
            cboCntr_Corp_Cod.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCntrCorp);
            cboClient_Id.DataSource = dataProcessor.CopyIList<SfcorpDLL.ety.etyClient>(global.ilClient);
            cboWork_Way_Id.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilWorkWay);
            cboCntr_Siz_Cod.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCntrSize);
            cboCntr_Typ_Cod.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCntrType);
            cboCargo_Cod.DataSource = dataProcessor.CopyIList<etyCodeRef>(global.ilCargo);
            IList<etyCodeRef> ilSpcMod = dataProcessor.CopyIList<etyCodeRef>(global.ilBnsSpcMod);
            ilSpcMod.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboSpcMod.DataSource = ilSpcMod;
            IList<etyCodeRef> ilForeignVvd = dataProcessor.CopyIList<etyCodeRef>(global.ilForeignVvd);
            ilForeignVvd.Insert(0, new TT.ORM.etyCodeRef() { CODE = "***", CODE_DESC = "***" });
            cboForeignVvd.DataSource = ilForeignVvd;
        }
        private void tbarRefresh_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                splashScreenManager1.ShowWaitForm();
            }
            catch { }
            RefreshDate();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }

        private void tbarNew_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                splashScreenManager1.ShowWaitForm();
            }
            catch { }
            NewData();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }

        private void tbarSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                splashScreenManager1.ShowWaitForm();
            }
            catch { }
            SaveDate();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }

        private void tbarDelete_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            try
            {
                splashScreenManager1.ShowWaitForm();
            }
            catch { }
            DeleteDate();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }

        //搜索
        public override etyQuickKey F7()
        {
            etyFrtAgyBns eyBns = new etyFrtAgyBns();
            IList<QueryItem> ilQueryItem = new List<QueryItem>();
            ilQueryItem = this.GetQueryItemFromLabel(this, ref ilQueryItem);
            //日期手工加处理
            foreach (QueryItem eyItem in ilQueryItem)
            {
                if (eyItem.FieldName.IndexOf("_TIM") > 0 || eyItem.FieldName.IndexOf("_DATE") > 0)
                {
                    eyItem.DataType = typeof(DateTime);
                }
            }

            IList<etyUserProfile> ilUserProj = new List<etyUserProfile>();
            etyUserProfile ey = new etyUserProfile();
            ey.IDENTITY = global.basSysPara.UserID;
            ey.PRES_OBJECT = this.Name;
            ey.TYPE_FLAG = "Q";
            frmQuery fmQuery = new frmQuery(ey, eyBns, ilQueryItem,global.basSysPara);
            if (fmQuery.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                eySqlWhere.SQL_WHERE = fmQuery.sqlString;
                RefreshDate();
            }
            return base.F7();
        }

        private void tbarSearch_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            F7();
        }

        private void tbarExit_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            F12();
        }

        public override Dev.Control.etyQuickKey RefreshDate()
        {
            //IList<etyFrtAgyBns> ilAngBns = bzAgyBnsSearch.GetAgyBnsSum(eySqlWhere);

            //srcBinding.DataSource = ilAngBns;
            //ggcDtl.DataSource = srcBinding;

            DataTable dt = bzAgyBnsSearch.GetAgyBnsSumTable(eySqlWhere);
            CreateGridHeard(dt);
            srcBinding.DataSource = dt;
            ggcDtl.DataSource = srcBinding;
            ggcDtl.AutoColumnWidth();
            return base.RefreshDate();
        }

        private void GetCboText()
        {
            cboPort_Id.GetCodeText();
            cboI_E_Id.GetCodeText();
            cboFee_Way_Id.GetCodeText();
            cboCustomer_Id.GetCodeText();
            cboCntr_Corp_Cod.GetCodeText();
            cboClient_Id.GetCodeText();
            cboCollaborate_Id.GetCodeText();
            cboWork_Way_Id.GetCodeText();
            cboCntr_Siz_Cod.GetCodeText();
            //cboCntr_Typ_Cod.GetCodeText();
            cboCargo_Cod.GetCodeText();
            cboSpcMod.GetCodeText();
            cboForeignVvd.GetCodeText();
        }

        private void ClearForm()
        {
            //清抬头
            txtContract_No.Text = "";
            cboPort_Id.SelectedIndex = -1;
            cboI_E_Id.SelectedIndex = -1;
            cboFee_Way_Id.SelectedIndex = -1;
            txtRec_Nam.Text = global.basSysPara.UserID;
            dateRec_Tim.DateTime = DateTime.Now;
            txtUpdate_Nam.Text = "";
            dateUpdate_Tim.DateTime = DateTime.Now;
            cboCustomer_Id.SelectedIndex = -1;
            cboCntr_Corp_Cod.SelectedIndex = 0;
            cboClient_Id.SelectedIndex = -1;
            txtClient_Contact.Text = "";

            //清网格
            IList<etyFrtAgyBnsCon> dtlList = new List<etyFrtAgyBnsCon>();
            srcBinding.DataSource = dtlList;
            ggcDtl.DataSource = srcBinding;
            ggcDtl.AutoColumnWidth();

            //清明细
            txtSea_Bill_No.Text = "";
            txtAgent_Bill_No.Text = "";
            txtBooking_No.Text = "";
            cboWork_Way_Id.SelectedIndex = -1;
            cboCntr_Siz_Cod.SelectedIndex = -1;
            cboCntr_Typ_Cod.SelectedIndex = -1;
            txtCntrCount.Text = "";
            txtShip_Nam.Text = "";
            txtVoyage.Text = "";
            cboCargo_Cod.SelectedIndex = -1;
            txtUndg_No.Text = "";
            chkWgtFlag.Checked = false;
            cboSpcMod.SelectedIndex = 0;
            cboCollaborate_Id.SelectedIndex = 0;
            cboForeignVvd.SelectedIndex = 2;
            delFabConList = new List<etyFrtAgyBns>();

            //下拉默认出口
            IList<etyCodeRef> ilIe = cboI_E_Id.DataSource as IList<etyCodeRef>;
            foreach (etyCodeRef ie in ilIe)
            {
                if (ie.CODE == "E")
                {
                    cboI_E_Id.SelectedItem = ie;
                    cboI_E_Id.GetCodeText();
                }
            }
            //下拉默认陆运重进
            IList<etyCodeRef> ilWorkWay = cboWork_Way_Id.DataSource as IList<etyCodeRef>;
            foreach (etyCodeRef iWorkWay in ilWorkWay)
            {
                if (iWorkWay.CODE == "FINO")
                {
                    cboWork_Way_Id.SelectedItem = iWorkWay;
                    cboWork_Way_Id.GetCodeText();
                }
            }
            //内外贸
            cboForeignVvd.GetCodeText();
            cboCollaborate_Id.GetCodeText();
            xtraTabControl1.SelectedTabPageIndex = 0;

            ilImageList.Clear();
            ilAddImgList.Clear();
            ilDelImgList.Clear();
            //srcImage.DataSource = ilImageList;
        }
        private bool check_hdr(etyFrtAgyBns ey)
        {
            if (string.IsNullOrEmpty(ey.PORT_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("码头不能为空");
                cboPort_Id.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.I_E_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("进出口标志不能为空");
                cboI_E_Id.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.FEE_WAY_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("结算方式不能为空");
                cboFee_Way_Id.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.COLLABORATE_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("合作方不能为空");
                cboCollaborate_Id.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.CUSTOMER_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("客户不能为空");
                cboCustomer_Id.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.CNTR_CORP_COD.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("合作方不能为空");
                cboCntr_Corp_Cod.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.CLIENT_ID.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("办单人不能为空");
                cboClient_Id.Focus();
                return false;
            }
            return true;
        }
        private bool check_dtl(etyFrtAgyBns ey)
        {
            //if (string.IsNullOrEmpty(ey.BOOKING_NO.Trim()))
            //{
            //    TT.HelpInfo.MsgBox.ShowWarnBox("SO送单号不能为空");
            //    txtBooking_No.Focus();
            //    return false;
            //}
            if (string.IsNullOrEmpty(ey.CNTR_SIZ_COD.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("箱尺寸不能为空");
                cboCntr_Siz_Cod.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(ey.CNTR_TYP_COD.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("箱类型不能为空");
                cboCntr_Typ_Cod.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(txtCntrCount.Text.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("箱数不能为空");
                txtCntrCount.Focus();
                return false;
            }
            int iCntrCount;
            if (!int.TryParse(txtCntrCount.Text.Trim(), out iCntrCount) || iCntrCount < 1)
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("箱数必须大于0");
                txtCntrCount.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(cboForeignVvd.Text.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("内外贸标识不能为空");
                cboForeignVvd.Focus();
                return false;
            }
            if (string.IsNullOrEmpty(cboSpcMod.Text.Trim()))
            {
                TT.HelpInfo.MsgBox.ShowWarnBox("特别处理不能为空");
                cboSpcMod.Focus();
                return false;
            }
            return true;
        }

        private void btnBuild_Click(object sender, EventArgs e)
        {
            etyFrtAgyBns ey = new etyFrtAgyBns();
            TT.Common.formProcess.GetFormEntity(ey, panelControl1);
            //TT.Common.formProcess.GetFormEntity(ey, panelControl2);
            if (!check_dtl(ey))
                return;
            IList<etyFrtAgyBns> dtlList;
            dtlList = srcBinding.DataSource as IList<etyFrtAgyBns>;
            if (dtlList == null || dtlList.Count < 1)
                dtlList = new List<etyFrtAgyBns>();
            for (int i = 0; i < int.Parse(txtCntrCount.Text.Trim()); i++)
            {
                //dtlList.Add((etyFrtAgyBns)ey.Clone()); 
                dtlList.Add(dataProcessor.CopyIList<etyFrtAgyBns>(new List<etyFrtAgyBns>() { ey })[0]);
            }
            srcBinding.DataSource = dtlList;
            ggcDtl.DataSource = srcBinding;
            ggcDtl.AutoColumnWidth();
        }

        private void cboClient_Id_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtClient_Contact.Text = cboClient_Id.GetValue("CLIENT_CONTACT");
        }

        private void txtContract_No_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                RefreshDate();
            }
        }

        private void ggcDtl_Click(object sender, EventArgs e)
        {
            etyFrtAgyBns ey = srcBinding.Current as etyFrtAgyBns;
            if (ey == null)
                return;
            TT.Common.formProcess.SetFormEntity(ey, panelControl1);
            //TT.Common.formProcess.SetFormEntity(ey, panelControl2);
            GetCboText();
            BindDtlControlEvent();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {

        }
        IList<etyFrtAgyBns> delFabConList = new List<etyFrtAgyBns>();
        private void btnRemove_Click(object sender, EventArgs e)
        {

        }

        bool isInitBillGrid = false;
        private void xtraTabControl1_SelectedPageChanged(object sender, DevExpress.XtraTab.TabPageChangedEventArgs e)
        {
            if (xtraTabControl1.TabIndex == 1 && !isInitBillGrid)
            {

            }

        }

        public object eyBill { get; set; }

        private void ggcDtl_DoubleClick(object sender, EventArgs e)
        {
            DataRowView dv = srcBinding.Current as DataRowView;
            IList<etyFrtAgyBns> lstBns = TT.Common.Converts.ConvertToIList<etyFrtAgyBns>(new DataRow[] { dv.Row});
            if (lstBns.Count <= 0) return;
            etyFrtAgyBns ey = lstBns[0];
            if (ey == null)
                return;
            try { splashScreenManager1.ShowWaitForm(); }    catch { }
            MainForm mainForm = this.MdiParent as MainForm;
            DevExpress.XtraBars.Docking2010.Views.BaseDocument document = null;
            Sfcorp.form.frmAgyBns frmBns;
            if (mainForm.Documents.TryGetValue("Bns", out document))
            {
                frmBns = document.Form as Sfcorp.form.frmAgyBns;
                frmBns.Close();
            }
            frmBns = new Sfcorp.form.frmAgyBns();
            frmBns.ContractNo = ey.CONTRACT_NO;
            frmBns.MOD_ID = "barBns";
            frmBns.MdiParent = this.MdiParent;
            frmBns.Show();
            try{ splashScreenManager1.CloseWaitForm();  } catch { }
        }
        private void BindDtlControlEvent()
        {
            foreach (System.Windows.Forms.Control ctrl in panelControl1.Controls)
            {
                if (ctrl is Dev.Control.cTextEdit)
                {
                    Dev.Control.cTextEdit txtBox = ctrl as Dev.Control.cTextEdit;
                    txtBox.TextChanged -= new EventHandler(DetailTextBoxChanged);
                    txtBox.TextChanged += new EventHandler(DetailTextBoxChanged);
                }
                else if (ctrl is Dev.Control.MultiColumnComboBox)
                {
                    Dev.Control.MultiColumnComboBox cboBox = ctrl as Dev.Control.MultiColumnComboBox;
                    cboBox.SelectedIndexChanged += new EventHandler(DetailCboSelIndexChanged);
                }
                else if (ctrl is Dev.Control.MultiColumnComboBox)
                {
                    Dev.Control.MultiColumnComboBox cboBox = ctrl as Dev.Control.MultiColumnComboBox;
                    cboBox.SelectedIndexChanged -= new EventHandler(DetailCboSelIndexChanged);
                    cboBox.SelectedIndexChanged += new EventHandler(DetailCboSelIndexChanged);
                }
                else if (ctrl is Dev.Control.cCheckBox)
                {
                    Dev.Control.cCheckBox chkBox = ctrl as Dev.Control.cCheckBox;
                    chkBox.CheckedChanged -= new EventHandler(DetailChkBoxChanged);
                    chkBox.CheckedChanged += new EventHandler(DetailChkBoxChanged);
                }
            }
        }
        private void RemoveDtlControlEvent()
        {
            foreach (System.Windows.Forms.Control ctrl in panelControl1.Controls)
            {
                if (ctrl is Dev.Control.cTextEdit)
                {
                    Dev.Control.cTextEdit txtBox = ctrl as Dev.Control.cTextEdit;
                    txtBox.TextChanged -= new EventHandler(DetailTextBoxChanged);
                }
                else if (ctrl is Dev.Control.MultiColumnComboBox)
                {
                    Dev.Control.MultiColumnComboBox cboBox = ctrl as Dev.Control.MultiColumnComboBox;
                    cboBox.SelectedIndexChanged -= new EventHandler(DetailCboSelIndexChanged);
                }
                else if (ctrl is Dev.Control.MultiColumnComboBox)
                {
                    Dev.Control.MultiColumnComboBox cboBox = ctrl as Dev.Control.MultiColumnComboBox;
                    cboBox.SelectedIndexChanged += new EventHandler(DetailCboSelIndexChanged);
                }
                else if (ctrl is Dev.Control.cCheckBox)
                {
                    Dev.Control.cCheckBox chkBox = ctrl as Dev.Control.cCheckBox;
                    chkBox.CheckedChanged -= new EventHandler(DetailChkBoxChanged);
                }
            }
        }
        private void DetailTextBoxChanged(object sender, EventArgs e)
        {
            EditDetailGrid();
        }

        private void DetailCboSelIndexChanged(object sender, EventArgs e)
        {
            EditDetailGrid();
        }

        private void DetailChkBoxChanged(object sender, EventArgs e)
        {
            EditDetailGrid();
        }
        private void EditDetailGrid()
        {
            etyFrtAgyBns ey = srcBinding.Current as etyFrtAgyBns;
            if (ey == null)
            {
                //TT.HelpInfo.MsgBox.ShowWarnBox("请先选择列表中的记录来编辑");
                return;
            }
            TT.Common.formProcess.GetFormEntity(ey, panelControl1);
            //TT.Common.formProcess.GetFormEntity(ey, panelControl2);
            srcBinding.ResetCurrentItem();
        }

        private void gridView1_CellValueChanged(object sender, CellValueChangedEventArgs e)
        {
            if (e.Column.Name == "CNTR")
            {
                string cntr = e.Value.ToString();
                if (!string.IsNullOrWhiteSpace(cntr))
                {
                    if (!TT.Common.ContainerProcess.ContainerNumberCheck(cntr))
                    {
                        TT.HelpInfo.MsgBox.ShowWarnBox("柜号:" + cntr + "校验失败，请重新输入");
                    }
                }
            }
        }
        private void gridView2_RowUpdated(object sender, RowObjectEventArgs e)
        {
            //etyChargeDtl etyChrgDtl = e.Row as etyChargeDtl;
            //if (etyChrgDtl != null && !ilCreateBill.Contains(etyChrgDtl) && !ilModifyBill.Contains(etyChrgDtl))
            //    ilModifyBill.Add(etyChrgDtl);
        }

        private void chkViewSum_CheckedChanged(object sender, EventArgs e)
        {
            //CreateGridHeard();
        }

        private void CreateGridHeard(DataTable dtSource)
        {
            sGridHead = "[CONTRACT_DATE;接单日期],[CONTRACT_NO;业务单号],[BNS_STATUS_D;状态],[PORT_NAM;码头名称],[CUSTOMER_NAME;客户名称],[I_E_NAM;进出口],[FOREIGN_VVD_DESC;内外贸],[WORK_WAY_NAM;作业类型],[SEA_BILL_NO;提单号],[BOX20;20尺{0}NULL{0}SUM],[BOX40;40尺{0}NULL{0}SUM],[BOX45;45尺{0}NULL{0}SUM],[TEU;TEU{0}NULL{0}SUM],[REC_NAM;创建人],[UPDATE_NAM;修改人],[UPDATE_TIM;修改时间],[I_AMOUNT;应收{0}NULL{0}SUM],[O_AMOUNT;应付{0}NULL{0}SUM],[REMARK;备注]";
            if (dtSource != null)
            {
                foreach (DataColumn dc in dtSource.Columns)
                {
                    if (sGridHead.IndexOf("[" + dc.ColumnName) < 0)
                    {
                        sGridHead += string.Format(",[{0};{1}]", new string[] { dc.ColumnName, dc.ColumnName }).Replace("]","{0}NULL{0}SUM]");
                    }
                }
            }
            if (chkViewSum.Checked)
            {
                sGridHead = string.Format(sGridHead, new string[] { stringProcess.Separator_Symbol });
                ggcDtl.GridView.OptionsView.ShowFooter = true;
            }
            else
            {
                sGridHead = sGridHead.Replace("{0}NULL{0}SUM", "");
                ggcDtl.GridView.OptionsView.ShowFooter = false;
            }
            ggcDtl.ColumnsMappingCreate(sGridHead);
            this.winUtil.LoadGridLayout(ggcDtl);
        }

        private void gridView1_CustomDrawCell(object sender, RowCellCustomDrawEventArgs e)
        {
            if (gridView1.GetRow(e.RowHandle) == null)
                return;
            else
            {
                //etyFrtAgyBns pe = gridView1.GetRow(e.RowHandle) as etyFrtAgyBns;
                DataRowView dv = gridView1.GetRow(e.RowHandle) as DataRowView;
                IList<etyFrtAgyBns> lstBns = TT.Common.Converts.ConvertToIList<etyFrtAgyBns>(new DataRow[] { dv.Row });
                if (lstBns.Count <= 0) return;
                etyFrtAgyBns ey = lstBns[0];
                if (ey == null)
                    return;
                switch (ey.BNS_STATUS)
                {
                    case "D":
                        e.Appearance.BackColor = Color.Silver;
                        break;
                    case "N":
                        e.Appearance.BackColor = Color.PaleGreen;
                        break;
                    default:
                        break;
                }
            }
        }
    }
}
